package cn.edu.scau.dao;

import cn.edu.scau.entity.GoOutRegister;
import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

@Mapper
@CacheNamespace
public interface GoOutRegisterMapper {
    @Delete({
        "delete from gooutregister",
        "where gooutDate = #{gooutdate,jdbcType=DATE}",
          "and expectedBackDate = #{expectedbackdate,jdbcType=DATE}"
    })
    int deleteByPrimaryKey(@Param("gooutdate") Date gooutdate, @Param("expectedbackdate") Date expectedbackdate);

    @Insert({
        "insert into gooutregister (gooutDate, expectedBackDate, ",
        "customerID, actuallyBackDate, ",
        "gooutReason)",
        "values (#{gooutdate,jdbcType=DATE}, #{expectedbackdate,jdbcType=DATE}, ",
        "#{customerid,jdbcType=INTEGER}, #{actuallybackdate,jdbcType=DATE}, ",
        "#{gooutreason,jdbcType=VARCHAR})"
    })
    int insert(GoOutRegister record);

    @InsertProvider(type=GoOutRegisterSqlProvider.class, method="insertSelective")
    int insertSelective(GoOutRegister record);

    @Select({
        "select",
        "gooutDate, expectedBackDate, customerID, actuallyBackDate, gooutReason",
        "from gooutregister",
        "where gooutDate = #{gooutdate,jdbcType=DATE}",
          "and expectedBackDate = #{expectedbackdate,jdbcType=DATE}"          
    })
    @Results({
        @Result(column="gooutDate", property="gooutdate", jdbcType=JdbcType.DATE, id=true),
        @Result(column="expectedBackDate", property="expectedbackdate", jdbcType=JdbcType.DATE, id=true),
        @Result(column="customerID", property="customerid", jdbcType=JdbcType.INTEGER),
        @Result(column="actuallyBackDate", property="actuallybackdate", jdbcType=JdbcType.DATE),
        @Result(column="gooutReason", property="gooutreason", jdbcType=JdbcType.VARCHAR)
    })
    GoOutRegister selectByPrimaryKey(@Param("gooutdate") Date gooutdate, @Param("expectedbackdate") Date expectedbackdate);

    @Select({
        "select",
        "gooutDate, expectedBackDate, customerID, actuallyBackDate, gooutReason",
        "from gooutregister",
        "where customerID = #{customerID,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="gooutDate", property="gooutdate", jdbcType=JdbcType.DATE, id=true),
        @Result(column="expectedBackDate", property="expectedbackdate", jdbcType=JdbcType.DATE, id=true),
        @Result(column="customerID", property="customerid", jdbcType=JdbcType.INTEGER),
        @Result(column="actuallyBackDate", property="actuallybackdate", jdbcType=JdbcType.DATE),
        @Result(column="gooutReason", property="gooutreason", jdbcType=JdbcType.VARCHAR)
    })
    List<GoOutRegister> selectByCustomerId(@Param("customerID")Integer customerID);

    
    @Select({
        "select",
        "gooutDate, expectedBackDate, customerID, actuallyBackDate, gooutReason",
        "from gooutregister"
    })
    @Results({
        @Result(column="gooutDate", property="gooutdate", jdbcType=JdbcType.DATE, id=true),
        @Result(column="expectedBackDate", property="expectedbackdate", jdbcType=JdbcType.DATE, id=true),
        @Result(column="customerID", property="customerid", jdbcType=JdbcType.INTEGER),
        @Result(column="actuallyBackDate", property="actuallybackdate", jdbcType=JdbcType.DATE),
        @Result(column="gooutReason", property="gooutreason", jdbcType=JdbcType.VARCHAR)
    })
    List<GoOutRegister> selectAll();

    @UpdateProvider(type=GoOutRegisterSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(GoOutRegister record);

    @Update({
        "update gooutregister",
        "set customerID = #{customerid,jdbcType=INTEGER},",
          "actuallyBackDate = #{actuallybackdate,jdbcType=DATE},",
          "gooutReason = #{gooutreason,jdbcType=VARCHAR}",
        "where gooutDate = #{gooutdate,jdbcType=DATE}",
          "and expectedBackDate = #{expectedbackdate,jdbcType=DATE}"
    })
    int updateByPrimaryKey(GoOutRegister record);
}